/**
 * 订单管理管理初始化
 */
var TOrder = {
    id: "TOrderTableSuper",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
TOrder.initColumn = function () {
    return [
        {type: 'checkbox', fixed: 'left',fixed: 'left'},
        {title: '编号', field: 'originalNum',width: 280, visible: true, align: 'center', valign: 'middle',fixed: 'left'},
        {title: '上游物流', field: 'sendDeptName',width: 180, visible: true, align: 'center', valign: 'middle',fixed: 'left'},
        {title: '收货人', field: 'consignee',width: 180, visible: true, align: 'center', valign: 'middle',fixed: 'left'},
        {title: '物品名称', field: 'goodsName',width: 180, visible: true, align: 'center', valign: 'middle',fixed: 'left'},
        {title: '重量', field: 'goodsWeight',width: 80, visible: true, align: 'center', valign: 'middle'},
        {title: '体积', field: 'goodsVolume',width: 80, visible: true, align: 'center', valign: 'middle'},
        {title: '件数', field: 'goodsPiece',width:80, visible: true, align: 'center', valign: 'middle'},
        {title: '回单要求', field: 'receipt',width: 120, visible: true, align: 'center', valign: 'middle'},
        {title: '财务情况', field: 'auditStatus',width: 120, visible: true, align: 'center', valign: 'middle'},
        {title: '订单状态', field: 'statusName',width: 120, visible: true, align: 'center', valign: 'middle'},
        {title: '入库时间', field: 'createtime',width: 120, visible: true, align: 'center', valign: 'middle'}

    ];
};

/**
 * 检查是否选中
 */
TOrder.check = function () {

    var selected = mTable.checkStatus(TOrder.id);
    // var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.data.length == 0 || selected.data.length > 1) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        TOrder.seItem = selected.data[0];
        return true;
    }
};

/**
 * 打开查看订单管理详情
 */
TOrder.openTOrderDetail = function () {

    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '订单管理详情',
            shade: 0.01,
            area: ['800px', '480px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/tOrder/tOrder_update/' + TOrder.seItem.id
        });
        this.layerIndex = index;
    }
};

TOrder.theLibrary = function () {
    if (this.check()) {
            var index = layer.open({
                type: 2,
                title: '订单出库',
                area: ['1150px', '450px'], //宽高
                fix: false, //不固定
                maxmin: true,
                content: Feng.ctxPath + '/tOrder/superlibrary/' + TOrder.seItem.id
            });
            layer.full(index);
            this.layerIndex = index;


    }
};

/**
 * 查询收银中心列表
 */
TOrder.search = function () {
    var dj_type=$("#dj_type").val()+"";
    var auditStatus=$("#audit_status").val()+"";
    var orderStatus=$("#orderStatus").val()+"";
    var status=$("#status").val()+"";
    if(orderStatus=="0"){
        orderStatus="";
    }
    var queryData = {};
    queryData['name'] = $("#name").val();
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();
    queryData['dj_type'] = dj_type;
    queryData['orderStatus'] = orderStatus;
    queryData['auditStatus'] = auditStatus;
    queryData['status'] = status;
    // alert( $("#dj_type").val());
    aTable.refresh(queryData);
};

/**
 * 删除订单管理
 */
TOrder.updateStatus = function () {

        var ajax = new $ax(Feng.ctxPath + "/tOrder/updateStatus", function (data) {
            Feng.success("操作成功!");
            aTable.refresh();
        }, function (data) {
            Feng.error("操作失败!" + data.responseJSON.message + "!");
        });
        ajax.set("tOrderId", $('#id').val());
        ajax.start();

};

var aTable = null
var mTable = null;
$(function () {
    var defaultColunms = TOrder.initColumn();
    aTable = new LYTable(TOrder.id,  "/tOrder/superOrderList", defaultColunms);
    // table.setPaginationType("client");
    layui.use('table', function () {
        mTable = layui.table;
        TOrder.table = aTable.init(mTable);
    });



    $('#dj_type').selectpicker({
        style: 'btn btn-select',
        noneSelectedText:"单据类型"
    });
    $('#audit_status').selectpicker({
        style: 'btn btn-select',
        noneSelectedText:"运单状态"
    });

    $('#status').selectpicker({
        style: 'btn btn-select',
        noneSelectedText:"出库状态"
    });

});

